package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.beehive.controls.api.bean.Control;

import canss.supports.basic;
import canss.webservice.model.ContentsDBContent;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtTRChannelGetOneMeta extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet
{

	private static final long serialVersionUID = 5794171288376383480L;

	public svtTRChannelGetOneMeta()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	@Control
	PortalIntraWebServiceControl control; // control = (control==null)?new
											// PortalIntraWebServiceControlBean():control;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();

		String _notxml = request.getParameter("_notxml");
		String _cid = request.getParameter("_cid");

		if (_notxml != null)
		{// in html
			out.write("doesn't support raw html.<br/>");

		} else
		{
			if(!basic.isEmpty(_cid))
			{
				control = (control==null)?new PortalIntraWebServiceControlBean():control;
				ContentsDBContent[] contents = control.getContentsByFilter("tblCID_cid=\""+_cid+"\"");
				out.write(ContentsDBContent.toXML(true, contents));
				return;
			}
		}
		out.write("error");
	}
}